// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import Element from 'element-ui'
import C from '@/assets/js/common.js'
Vue.use(Element)
Vue.prototype.C = C
if (!process.env.IS_WEB) Vue.use(require('vue-electron'))

Vue.config.productionTip = false

/* 路由统一验证 */
router.beforeEach((to, from, next) => {
  // 判断该路由是否需要登录权限
  if (to.meta.needlogin) {
    // 通过vuex state获取当前的token是否存在
    let userinfo = C.getLocalStorage('userinfo')
    if (!userinfo) {
      C.sendstore('next', next)
      next({ path: '/userlogin' })
    } else {
      next()
    }
  } else {
    next()
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})
